package com.xinghou.platform.dao.bases.util;

public class StringUtils {
	
	/**
	 * 判断一个字符串是否为穷或null
	 * @param str
	 * @return
	 */
	public static boolean isNullOrEmpty(String str){
		return str == null ||"null".equalsIgnoreCase(str.trim())|| "".equals(str.trim()) ? true : false;
	}
	
	
	public static StringBuffer subStringBuffer(StringBuffer sql){
		return subStringBuffer(sql,",");
	}
	
	public static StringBuffer subStringBuffer(StringBuffer sql,String symbol){
		return  new StringBuffer(sql.substring(0, sql.lastIndexOf(symbol)));
	}
	
	/**
	 * 往Sql in语句中添加()中的内容 
	 * 如select * from a where a.id in (1,2,3);
	 * @param sql
	 * @param ColumnNames
	 */
	public static StringBuffer addSQLIn(StringBuffer sql , String columnName,Object[] columnValues){
		if(columnValues == null) {
			return sql;
		}
		sql.append(columnName);
		sql.append(" in (");
		for(Object obj : columnValues){
			if(obj instanceof String)
				sql.append("'");
			sql.append(obj.toString());
			if(obj instanceof String)
				sql.append("'");
			sql.append(",");
		}
		sql = subStringBuffer(sql);
		sql.append(" )"); 
		return sql;
	}
	
}
